home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / forms / frmwiz / genform.frm < prev    next >
Text File  |  1995-01-14  |  13KB  |  429 lines

  1. VERSION 2.00
  2. Begin Form GenForm 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "Form Wizard - Generate Form"
  5.    ClientHeight    =   2610
  6.    ClientLeft      =   2085
  7.    ClientTop       =   1380
  8.    ClientWidth     =   7365
  9.    ControlBox      =   0   'False
  10.    Height          =   3015
  11.    HelpContextID   =   32
  12.    Icon            =   GENFORM.FRX:0000
  13.    Left            =   2025
  14.    LinkTopic       =   "Form3"
  15.    MaxButton       =   0   'False
  16.    ScaleHeight     =   2610
  17.    ScaleWidth      =   7365
  18.    Top             =   1035
  19.    Width           =   7485
  20.    Begin SSCommand BtnHelp 
  21.       Caption         =   "&Help"
  22.       Font3D          =   2  'Raised w/heavy shading
  23.       Height          =   615
  24.       Left            =   5160
  25.       Picture         =   GENFORM.FRX:0302
  26.       TabIndex        =   11
  27.       Top             =   1500
  28.       Width           =   915
  29.    End
  30.    Begin TextBox TxtTmpltName 
  31.       BackColor       =   &H00C0C0C0&
  32.       Height          =   375
  33.       Left            =   1560
  34.       TabIndex        =   0
  35.       Tag             =   "Name of the form template"
  36.       Top             =   360
  37.       Width           =   4995
  38.    End
  39.    Begin SSCommand BtnFindTmplt 
  40.       AutoSize        =   2  'Adjust Button Size To Picture
  41.       Font3D          =   2  'Raised w/heavy shading
  42.       Height          =   600
  43.       Left            =   6660
  44.       Picture         =   GENFORM.FRX:0604
  45.       TabIndex        =   1
  46.       Tag             =   "Press to find the database"
  47.       Top             =   120
  48.       Width           =   600
  49.    End
  50.    Begin SSPanel cMsg 
  51.       Align           =   2  'Align Bottom
  52.       Alignment       =   1  'Left Justify - MIDDLE
  53.       BevelInner      =   1  'Inset
  54.       BorderWidth     =   2
  55.       Height          =   375
  56.       Left            =   0
  57.       TabIndex        =   8
  58.       Top             =   2235
  59.       Width           =   7365
  60.    End
  61.    Begin SSCommand BtnFinish 
  62.       AutoSize        =   2  'Adjust Button Size To Picture
  63.       Caption         =   "&Finish"
  64.       Font3D          =   2  'Raised w/heavy shading
  65.       Height          =   615
  66.       Left            =   4260
  67.       Picture         =   GENFORM.FRX:0906
  68.       TabIndex        =   7
  69.       Tag             =   "Generate the form code"
  70.       Top             =   1500
  71.       Width           =   915
  72.    End
  73.    Begin SSCommand BtnCancel 
  74.       AutoSize        =   2  'Adjust Button Size To Picture
  75.       Caption         =   "&Cancel"
  76.       Font3D          =   2  'Raised w/heavy shading
  77.       Height          =   615
  78.       Left            =   3360
  79.       Picture         =   GENFORM.FRX:0C08
  80.       TabIndex        =   6
  81.       Tag             =   "Cancel building the form"
  82.       Top             =   1500
  83.       Width           =   915
  84.    End
  85.    Begin SSCommand BtnNext 
  86.       AutoSize        =   2  'Adjust Button Size To Picture
  87.       Caption         =   "&Next"
  88.       Enabled         =   0   'False
  89.       Font3D          =   2  'Raised w/heavy shading
  90.       Height          =   615
  91.       Left            =   2460
  92.       Picture         =   GENFORM.FRX:0F0A
  93.       TabIndex        =   5
  94.       Top             =   1500
  95.       Width           =   915
  96.    End
  97.    Begin SSCommand BtnPrev 
  98.       AutoSize        =   2  'Adjust Button Size To Picture
  99.       Caption         =   "&Previous"
  100.       Font3D          =   2  'Raised w/heavy shading
  101.       Height          =   615
  102.       Left            =   1560
  103.       Picture         =   GENFORM.FRX:120C
  104.       TabIndex        =   4
  105.       Tag             =   "Return to previous step"
  106.       Top             =   1500
  107.       Width           =   915
  108.    End
  109.    Begin TextBox TxtFrmName 
  110.       BackColor       =   &H00C0C0C0&
  111.       Height          =   375
  112.       Left            =   1560
  113.       TabIndex        =   2
  114.       Tag             =   "Name to save the form as"
  115.       Top             =   1020
  116.       Width           =   4995
  117.    End
  118.    Begin SSCommand BtnFindForm 
  119.       AutoSize        =   2  'Adjust Button Size To Picture
  120.       Font3D          =   2  'Raised w/heavy shading
  121.       Height          =   600
  122.       Left            =   6660
  123.       Picture         =   GENFORM.FRX:150E
  124.       TabIndex        =   3
  125.       Tag             =   "Press to find the database"
  126.       Top             =   780
  127.       Width           =   600
  128.    End
  129.    Begin CommonDialog CMDialog1 
  130.       DefaultExt      =   "frm"
  131.       DialogTitle     =   "Save Form As"
  132.       Filter          =   "VB Forms|*.frm"
  133.       Left            =   300
  134.       Top             =   1380
  135.    End
  136.    Begin Label Label1 
  137.       Alignment       =   1  'Right Justify
  138.       AutoSize        =   -1  'True
  139.       BackColor       =   &H00C0C0C0&
  140.       Caption         =   "Form Name"
  141.       ForeColor       =   &H00FF0000&
  142.       Height          =   195
  143.       Index           =   2
  144.       Left            =   525
  145.       TabIndex        =   10
  146.       Top             =   1080
  147.       Width           =   960
  148.    End
  149.    Begin Label Label1 
  150.       Alignment       =   1  'Right Justify
  151.       AutoSize        =   -1  'True
  152.       BackColor       =   &H00C0C0C0&
  153.       Caption         =   "Form Template"
  154.       ForeColor       =   &H00FF0000&
  155.       Height          =   195
  156.       Index           =   3
  157.       Left            =   225
  158.       TabIndex        =   9
  159.       Top             =   420
  160.       Width           =   1260
  161.    End
  162. End
  163. Option Explicit
  164.     Dim stemplate As String, sForm As String    ' names for template and form files
  165.     Dim sFormLine As String, msg As String
  166.     Dim indent As Integer           ' number spaces to indent line
  167.     Dim iNumLabelLines As Integer   ' number of lines in label control definition
  168.     Dim sLabelLines() As String     ' lines in label definition
  169.     Dim iNumTextLines As Integer    ' number of lines in Text control definition
  170.     Dim sTextLines() As String      ' lines in textbox definition
  171.     Dim dSvLabel1Top As Double      ' save area for label1 top
  172.     Dim dSvLabel1Left As Double     ' save area for label1 left
  173.     Dim dSvLabel2Top As Double      ' save area for label2 top
  174.     Dim dLabelInc As Double         ' amount to increment each label top by
  175.     Dim dSvText1Top As Double       ' save area for textbox1 top
  176.     Dim dSvText1Left As Double      ' save area for textbox1 left
  177.     Dim dSvText2Top As Double       ' save area for textbox2 top
  178.     Dim dTextInc As Double          ' amount to increment each textbox top by
  179.  
  180. Sub BtnCancel_Click ()
  181.     EndItNow
  182.  
  183. End Sub
  184.  
  185. Sub BtnCancel_GotFocus ()
  186.     cMsg.Caption = BtnCancel.Tag
  187.  
  188. End Sub
  189.  
  190. Sub BtnCancel_LostFocus ()
  191.     cMsg.Caption = ""
  192.  
  193. End Sub
  194.  
  195. Sub BtnFindForm_Click ()
  196.     CMDialog1.DialogTitle = "Save Form As"
  197.     CMDialog1.Filename = CaptnFrm.TxtName & ".Frm"
  198.     CMDialog1.Flags = OFN_OVERWRITEPROMPT + OFN_PATHMUSTEXIST
  199.     CMDialog1.Action = 2
  200.     If CMDialog1.Filename <> "" Then
  201.         TxtFrmName.Text = CMDialog1.Filename
  202.     End If
  203.  
  204. End Sub
  205.  
  206. Sub BtnFindForm_GotFocus ()
  207.     cMsg.Caption = BtnFindForm.Caption
  208.  
  209. End Sub
  210.  
  211. Sub BtnFindTmplt_Click ()
  212.     CMDialog1.DialogTitle = "Select Form Template"
  213.     CMDialog1.Filename = ""
  214.     CMDialog1.Flags = OFN_FILEMUSTEXIST
  215.     CMDialog1.Action = 1
  216.     If CMDialog1.Filename <> "" Then
  217.         TxtTmpltName = CMDialog1.Filename
  218.     End If
  219.  
  220. End Sub
  221.  
  222. Sub BtnFindTmplt_GotFocus ()
  223.     cMsg.Caption = BtnFindTmplt.Caption
  224.  
  225. End Sub
  226.  
  227. Sub BtnFinish_Click ()
  228.     Dim msg As String
  229.     On Error GoTo GenerateErr
  230.  
  231.     mousepointer = HOURGLASS
  232.     ' Verify that file names are correct
  233.     stemplate = TxtTmpltName.Text
  234.     If Right$(UCase$(TxtFrmName.Text), 4) <> ".FRM" Then
  235.         TxtFrmName.Text = TxtFrmName.Text & ".FRM"
  236.     End If
  237.     sForm = TxtFrmName.Text
  238.     If stemplate = "" Then
  239.         Beep
  240.         mousepointer = DEFAULT
  241.         MsgBox "You must specify a form template or use the file drawer button to locate a form template.", 0 + 48 + 0 + 0, "Form Template Error"
  242.         TxtTmpltName.SetFocus
  243.         Exit Sub
  244.     End If
  245.     If Dir$(stemplate) = "" Then
  246.         Beep
  247.         mousepointer = DEFAULT
  248.         MsgBox "The form template you have specified does not exist!  Use the file drawer button to locate a form template.", 0 + 48 + 0 + 0, "Form Template Error"
  249.         TxtTmpltName.SetFocus
  250.         Exit Sub
  251.     End If
  252.     If sForm = "" Then
  253.         Beep
  254.         mousepointer = DEFAULT
  255.         MsgBox "You must specify a form name or use the file drawer button to locate a form.", 0 + 48 + 0 + 0, "Form Save Error"
  256.         TxtFrmName.SetFocus
  257.         Exit Sub
  258.     End If
  259.     If sForm = stemplate Then
  260.         Beep
  261.         mousepointer = DEFAULT
  262.         MsgBox "You cannot use the template as the output form.", 0 + 48 + 0 + 0, "Form Save Error"
  263.         TxtFrmName.SetFocus
  264.         Exit Sub
  265.     End If
  266.     On Error GoTo erropeningtemplate
  267.     Open stemplate For Input Access Read Lock Write As #1
  268.     On Error GoTo erropeningform
  269.     Open sForm For Output Access Write Lock Read Write As #2
  270.     On Error GoTo GenerateErr
  271.     indent = 0
  272.  
  273.     Do While Not EOF(1)
  274.         Input #1, sFormLine
  275.         Select Case True
  276.         Case InStr(1, sFormLine, "Begin Form", 1) <> 0      ' Beginning of form
  277.             Print #2, "Begin Form " & CaptnFrm.TxtName.Text
  278.             indent = 3
  279.         Case InStr(1, sFormLine, "Caption", 1) <> 0         ' Form Caption line
  280.             Print #2, Spc(indent); "Caption = " & Chr$(34) & CaptnFrm.TxtCaption.Text & Chr$(34)
  281.         Case InStr(1, sFormLine, "Begin ", 1) <> 0    ' Beginning of control
  282.             Select Case True
  283.             Case InStr(1, sFormLine, " Lbl1", 1) <> 0   ' Beginning of label 1
  284.                 SaveLabel1
  285.             Case InStr(1, sFormLine, " Lbl2", 1) <> 0   ' Beginning of label 2
  286.                 SaveLabel2
  287.             Case InStr(1, sFormLine, " Fld1", 1) <> 0   ' Beginning of field 1
  288.                 SaveField1
  289.             Case InStr(1, sFormLine, " Fld2", 1) <> 0   ' Beginning of field 2
  290.                 SaveField2
  291.             Case InStr(1, sFormLine, " Data", 1) <> 0   ' Beginning of data control
  292.                 SaveDataCtrl
  293.             Case Else               ' Beginning of other control
  294.                 SaveControl
  295.             End Select
  296.         Case InStr(1, sFormLine, "End", 1) <> 0                 ' End of form
  297.             If Len(sFormLine) < InStr(1, sFormLine, "End", 1) + 4 Then
  298.                 GotEndOfForm
  299.             Else
  300.                 Print #2, Spc(indent); sFormLine        ' Output any unrecognized lines as is
  301.             End If
  302.         Case Else
  303.             Print #2, Spc(indent); sFormLine        ' Output any unrecognized lines as is
  304.         End Select
  305.  
  306.     Loop
  307.  
  308.     Close #1
  309.     Close #2
  310.     msg = "Form " & sForm & " generated."
  311.     Beep
  312.     mousepointer = DEFAULT
  313.     MsgBox msg, MB_ICONINFORMATION, "Form Wizard Generation"
  314.     
  315.     db.Close        ' Close the database
  316.     Unload CaptnFrm     ' Unload all forms
  317.     Unload DataSpec
  318.     Unload FieldFrm
  319.     MainForm.Show MODELESS
  320.     Unload GenForm
  321.     
  322.     Exit Sub
  323.  
  324. GenerateErr:
  325.     erraction = RB_ErrorHandler("GenForm", "BtnFinish_Click")
  326.     Select Case erraction
  327.     Case 1
  328.         Resume 0      ' Retry option selected
  329.     Case 2
  330.         Resume Next   ' Ignore option selected
  331.     End Select
  332.     On Error Resume Next
  333.     Close #1, #2
  334.     On Error GoTo GenerateErr
  335.     Exit Sub
  336.  
  337. erropeningtemplate:
  338.         Beep
  339.         mousepointer = DEFAULT
  340.         msg = "A " & Error & " error has occurred opening the template file!  Please correct and retry the function"
  341.         MsgBox msg, 0 + 48 + 0 + 0, "Form Template Error"
  342.         TxtTmpltName.SetFocus
  343.         Close #1, #2
  344.         On Error GoTo GenerateErr
  345.         Exit Sub
  346.  
  347. erropeningform:
  348.         Beep
  349.         mousepointer = DEFAULT
  350.         msg = "A " & Error & " error has occurred opening the output form file!  Please correct and retry the function"
  351.         MsgBox msg, 0 + 48 + 0 + 0, "Form Output Error"
  352.         TxtTmpltName.SetFocus
  353.         Exit Sub
  354.  
  355. End Sub
  356.  
  357. Sub BtnFinish_GotFocus ()
  358.     cMsg.Caption = BtnFinish.Tag
  359.  
  360. End Sub
  361.  
  362. Sub BtnFinish_LostFocus ()
  363.     cMsg.Caption = ""
  364.  
  365. End Sub
  366.  
  367. Sub BtnHelp_Click ()
  368.     SendKeys "{F1}"
  369.  
  370. End Sub
  371.  
  372. Sub BtnPrev_Click ()
  373.     FieldFrm.Show MODELESS
  374.     GenForm.Hide
  375.  
  376. End Sub
  377.  
  378. Sub BtnPrev_GotFocus ()
  379.     cMsg.Caption = BtnPrev.Tag
  380.  
  381. End Sub
  382.  
  383. Sub BtnPrev_LostFocus ()
  384.     cMsg.Caption = ""
  385.  
  386. End Sub
  387.  
  388. Sub FldGotFocus (PControl As Control)
  389.     PControl.BackColor = BLUE
  390.     PControl.ForeColor = WHITE
  391.     PControl.SelStart = 0
  392.     PControl.SelLength = 1000
  393.     cMsg.Caption = PControl.Tag
  394.  
  395. End Sub
  396.  
  397. Sub FldLostFocus (PControl As Control)
  398.     PControl.BackColor = RB_GRAY
  399.     PControl.ForeColor = BLACK
  400.     cMsg.Caption = ""
  401.  
  402. End Sub
  403.  
  404. Sub Form_Paint ()
  405.     Form3d Me
  406.  
  407. End Sub
  408.  
  409. Sub TxtFrmName_GotFocus ()
  410.     FldGotFocus TxtFrmName
  411.  
  412. End Sub
  413.  
  414. Sub TxtFrmName_LostFocus ()
  415.     FldLostFocus TxtFrmName
  416.  
  417. End Sub
  418.  
  419. Sub TxtTmpltName_GotFocus ()
  420.     FldGotFocus TxtTmpltName
  421.  
  422. End Sub
  423.  
  424. Sub TxtTmpltName_LostFocus ()
  425.     FldLostFocus TxtTmpltName
  426.  
  427. End Sub
  428.  
  429.